package LeetCode.LeetCodeHot;

import java.util.concurrent.ThreadLocalRandom;

import static Sort.SevenSort.swap;

/**
 * 颜色分类
 * @author lumin
 * @date 2022/05/07 15:00
 **/
public class Num75 {
    public void sortColors(int[] nums) {
        if(nums.length < 2){
            return;
        }
        int p0 = 0;
        int i = 0;
        int p2 = nums.length - 1;
        while(i <= p2){
            if(nums[i] == 0){
                swap(nums,p0,i);
                p0++;
                i++;
            }else if(nums[i] == 1){
                i++;
            }else{
                swap(nums,i,p2);
                p2--;
            }
        }
    }
    public void swap(int[] nums,int i,int j){
        int count = nums[i];
        nums[i] = nums[j];
        nums[j] = count;
    }
}